'use strict';
// 切换专家标题
function changeName(type){
  console.log($(this),66567)
  if(type==2){
    $("#expertClass2").removeAttr("class", "title-active");
    $("#expertClass3").removeAttr("class", "title-active");
    $("#expertClass1").addClass("title-active");
  }
  if(type==3){
    $("#expertClass1").removeAttr("class", "title-active");
    $("#expertClass3").removeAttr("class", "title-active");
    $("#expertClass2").addClass("title-active");
  }
  if(type==4){
    $("#expertClass1").removeAttr("class", "title-active");
    $("#expertClass2").removeAttr("class", "title-active");
    $("#expertClass3").addClass("title-active");
  }
  // if ($(this).hasClass('title-active')) {
  //   return;
  // }

  expertArr(type)
}
// 专家列表数据
function expertArr(type) {
  console.log(type,6656)
  $.server({ pageSize: 100, pageNum: 1, type : type ? type : '2' }, '/website/v1/lecturerList').then(function (res) {
    console.log(res, "专家列表");
    var expertArrList = res.result.data;
    if (expertArrList.length == 0) {
      $('#expertContent').html('暂无数据');
      return ;
    }
    var name = expertArrList[0].name + '/' + expertArrList[0].title + ' ' + expertArrList[0].introduction;
    $('#exportDescription').html(name);
    expert(expertArrList);
  });
}
function expert(obj) {
  var html = '',
      length = obj.length > 3 ? 3 : obj.length;

  for (var i = 0; i < length; i++) {
    html += ' <a onclick="expertDetail(' + obj[i].lecturerId + ')"><div class="topic-box expert-reset title-box col-md-12 col-sm-12 col-xs-12 mouseMethod">\n     <img src=' + obj[i].avatar + '>\n      <div class="word-box">\n          <div class="name-box"><span class="name">' + obj[i].name + '/</span><span class="name-r">' + obj[i].title + '</span></div>\n          <div class="description">' + obj[i].introduction + '</div>\n      </div>\n  </div></a>';
  }
  $("#expertContent").html(html);
}
//加载专家观点
function researchFindings() {
  // lecturerId待定
  var params = { contentType: 1, pageSize: 100, pageNum: 1 };
  $.server(params, '/website/v1/lecturerContent').then(function (res) {
    console.log(res, "专家观点");
    var obj = res.result.data;
    var html = '',
        length = obj.length > 6 ? 6 : obj.length;
    for (var i = 0; i < length; i++) {
      if (!obj[i].createTime) {
        obj[i].createTime = '';
      }
      html += '<a onclick="goLessonDetail(' + obj[i].contentId + ',\'\u4E13\u5BB6\',\'\u4E13\u5BB6\u89C2\u70B9\')"><div class="topic-box title-box col-md-12 col-sm-12 col-xs-12">\n    <div class="flex-box">\n    <div class="around"></div>\n    <div class="topic-title">' + obj[i].title + '</div>\n    </div>\n    <div class="more">' + obj[i].createTime.substring(5, 10) + '</div>\n    </div></div>';
    }
    $("#researchFindings").html(html);
  });
}

//加载研究报告
function expertReport() {
  // lecturerId待定
  var params = { contentType: 3, pageSize: 100, pageNum: 1 };
  $.server(params, '/website/v1/lecturerContent').then(function (res) {
    console.log(res, "研究报告");
    var obj = res.result.data;
    var html = '',
        length = obj.length > 8 ? 8 : obj.length;
    for (var i = 0; i < length; i++) {
      html += '<a onclick="goNewsDetail(' + obj[i].contentId + ',\'\u4E13\u5BB6\',\'\u7814\u7A76\u62A5\u544A\')"><div class="coolleges-w-box col-md-12 col-sm-12 col-xs-12">\n    <div class="topic-box expert-reset col-md-12 col-sm-12 col-xs-12" style="width:281.52px;height:144.77px">\n        <img class="book-img" src=\'' + obj[i].poster + '\'>\n        <div class="word-box book-reset">\n            <div class="name-box mouseMethod">' + obj[i].title + '</div>\n            <div class="description">' + obj[i].author + '</div>\n        </div>\n    </div>\n</div></div>';
    }
    $("#expertReport").html(html);
  });
}

// 页面顶部大图数据(待定)
function posterImg() {
  $.server({ location: 5 }, '/website/v1/getPoster').then(function (res) {
    console.log(res, "页面顶部大图数据");
    $('#bannerImg').attr("src", res.result.data[0].url);
  });
}
function more() {
  location.href = 'expertList.html';
}
function more1() {
  var id = 98;
  location.href = 'articleList.html?id=' + id + '&title=专家&text=专家观点';
}
// 跳转专家详情
function expertDetail(id) {
  location.href = 'expertDetail.html?id=' + id;
}
/**
 * 跳转到文章详情
 */
function goLessonDetail(id, word, childTitle) {
  location.href = 'industryDetail.html?id=' + id + '&word=' + word + '&childTitle=' + childTitle;
}
/**
 * 页面初始化时加载 window.onload
 */
$(function () {
  //调用server加载首页新闻
  posterImg();
  expertArr();
  researchFindings();
  expertReport();
  $(".moreyjbg").click(function(){
    var id= 99
    location.href='articleList.html?id=' + id + '&title=专家&text=研究报告';
  })
});
